import { VuexModule, Module, Mutation, Action, getModule } from 'vuex-module-decorators'
import store from '@/store'
import { getSidebarStatus, setSidebarStatus } from '@/service/setting'

export interface IAppState {
    sidebar: {
        opened: boolean
    }
}

@Module({ dynamic: true, store, name: 'app' })
class App extends VuexModule implements IAppState {
    public sidebar = {
        opened: getSidebarStatus()
    }

    @Mutation
    private TOGGLE_SIDEBAR() {
        this.sidebar.opened = !this.sidebar.opened
    }

    @Action
    public ToggleSideBar() {
        this.TOGGLE_SIDEBAR()
        setSidebarStatus(this.sidebar.opened)
    }
}
export const AppModule = getModule(App)
